//
//  ChatBarMoreViewItem.m
//  keyboard
//
//  Created by 遇水 on 16/3/12.
//  Copyright © 2016年 遇水. All rights reserved.
//

#import "ChatBarMoreViewItem.h"
#import "UIView+Extension.h"
#import "Masonry.h"

@interface ChatBarMoreViewItem ()

@property (nonatomic, strong) UIImageView    *imageView;

@property (nonatomic, strong) UILabel    *titleLabel;

@end

@implementation ChatBarMoreViewItem


-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initSubview];
    }
    
    return self;
}

-(void)setViewWithTitle:(NSString *)title imageName:(NSString *)imageName tag:(NSInteger)tag
{
        self.tag = tag;
        self.titleLabel.text = title;
        self.imageView.image = [UIImage imageNamed:imageName];
 
        [self updateConstraintsIfNeeded];
    
}


- (void)updateConstraints{
    [super updateConstraints];
    
    __block __typeof(self) weakSelf = self;
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.mas_top).with.offset(5);
        make.centerX.equalTo(weakSelf.mas_centerX);
        make.width.equalTo(@50);
        make.height.equalTo(@50);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.imageView.mas_bottom).with.offset(5);
        make.centerX.equalTo(weakSelf.mas_centerX);
    }];
}


/**
 *  初始化子控件
 */
-(void)initSubview
{
    UIImageView *imageView = [[UIImageView alloc]init];
    [self addSubview:imageView];
    self.imageView = imageView;
    
    UILabel *titleLabel  =[[UILabel alloc]init];
    titleLabel.font = [UIFont systemFontOfSize:13.0f];
    
    titleLabel.textColor = [UIColor darkGrayColor];
    [titleLabel setTextAlignment:NSTextAlignmentCenter];
    [self addSubview:titleLabel];
    self.titleLabel = titleLabel;
    
}


@end
